package com.example.hrms.Controller;

import com.example.hrms.Entity.Medicaldocuments;
import com.example.hrms.Entity.Medicalrecords;
import com.example.hrms.Service.MedicalrecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/medicalrecords")
public class MedicalrecordsController {

    @Autowired
    private MedicalrecordsService medicalrecordsService;

    @GetMapping("All")
    public Map<String, List<Medicalrecords>> All(){
        Map<String, List<Medicalrecords>> L = new HashMap<>();
        L.put("MedRec", medicalrecordsService.All());
        return L;
    }

    @RequestMapping("/Add")
    @ResponseBody
    public void AddMedDoc(Medicalrecords medicalrecords) {
        System.out.println(medicalrecords);
        medicalrecordsService.AddMedRec(medicalrecords);
    }

    @RequestMapping("Del")
    @ResponseBody
    public void Del(Medicalrecords medicalrecords){
        int id = medicalrecords.getId();
        medicalrecordsService.Del(id);
    }

    @GetMapping("/find")
    public Map<String, List<Medicalrecords>> Find(int id) {
        System.out.println(id+medicalrecordsService.Find(id).toString());

        Map<String, List<Medicalrecords>> response = new HashMap<>();
        response.put("MedDRec", medicalrecordsService.Find(id));
        return response;
    }

    @RequestMapping("Update")
    @ResponseBody
    public void update(Medicalrecords medicalrecords){
        medicalrecordsService.Update(medicalrecords);
    }
}

